<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function getRow(rowIndex) {
        let arr = []
        for (let i = 0; i <= rowIndex; i++) {
          // 二维数组，每行一开始都是一个空数组
          arr[i] = []
          for (let j = 0; j <= i; j++) {
            // 首尾项为1
            if (j === 0 || j === i) {
              arr[i][j] = 1
            } else {
              // 当前项 = 上一行的前一项 + 上一行的这一项
              arr[i][j] = arr[i-1][j-1] + arr[i-1][j]
            }
          }
        }
        return arr[rowIndex]
      }

      console.log(getRow(3))
    </script>
  </body>
</html>
